Skip to content

Conversation

@MaskRay
Copy link
Member

@MaskRay MaskRay commented May 19, 2025

When using -no-pie without a SECTIONS command, the linker uses the
target's default image base. If -Ttext= or --section-start specifies an
output section address below this base, the result is likely unintended.
LLD will give a diagnostic (#140187) and may change the behavior in the future.
It's good to set an explicit image base to avoid relying on its current
behavior. BOLT doesn't seem to care whether a PT_PHDR segment is
present.

Created using spr 1.3.5-bogner
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-bolt

Author: Fangrui Song (MaskRay)

Changes

When using -no-pie without a SECTIONS command, the linker uses the
target's default image base. If -Ttext= or --section-start specifies an
output section address below this base, the result is likely unintended.
LLD will give a diagnostic (#140187) and may change the behavior in the future.
It's good to set an explicit image base to avoid relying on its current
behavior. BOLT doesn't seem to care whether a PT_PHDR segment is
present.


Full diff: https://github.com/llvm/llvm-project/pull/140570.diff

5 Files Affected:

  • (modified) bolt/test/AArch64/check-init-not-moved.s (+1-1)
  • (modified) bolt/test/AArch64/pad-before-funcs.s (+1-1)
  • (modified) bolt/test/RISCV/reloc-jt.s (+1-1)
  • (modified) bolt/test/X86/double-rel-scan.s (+1-1)
  • (modified) bolt/test/X86/double-rel.s (+1-1)
diff --git a/bolt/test/AArch64/check-init-not-moved.s b/bolt/test/AArch64/check-init-not-moved.s
index ad4b80d2e60e2..bea0dbccfc8c0 100644
--- a/bolt/test/AArch64/check-init-not-moved.s
+++ b/bolt/test/AArch64/check-init-not-moved.s
@@ -5,7 +5,7 @@
 # address. Test checks that _init is not moved.
 
 # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
-# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static -Wl,--section-start=.data=0x1000 -Wl,--section-start=.init=0x1004
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static -Wl,--image-base=0,-Tdata=0x1000,--section-start=.init=0x1004
 # RUN: llvm-bolt %t.exe -o %t.bolt
 # RUN: llvm-nm %t.exe | FileCheck --check-prefix=CHECK-ORIGINAL %s
 # RUN: llvm-nm %t.bolt | FileCheck --check-prefix=CHECK-BOLTED %s
diff --git a/bolt/test/AArch64/pad-before-funcs.s b/bolt/test/AArch64/pad-before-funcs.s
index c1b92063d6fa4..49b30627ede4f 100644
--- a/bolt/test/AArch64/pad-before-funcs.s
+++ b/bolt/test/AArch64/pad-before-funcs.s
@@ -8,7 +8,7 @@
 
 
 # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
-# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -Wl,--section-start=.text=0x4000
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -Wl,--image-base=0x3000,--section-start=.text=0x4000
 # RUN: llvm-bolt %t.exe -o %t.bolt.0 --pad-funcs-before=_start:0
 # RUN: llvm-bolt %t.exe -o %t.bolt.4 --pad-funcs-before=_start:4
 # RUN: llvm-bolt %t.exe -o %t.bolt.8 --pad-funcs-before=_start:8
diff --git a/bolt/test/RISCV/reloc-jt.s b/bolt/test/RISCV/reloc-jt.s
index 009ce6cca95df..a1fc854f036da 100644
--- a/bolt/test/RISCV/reloc-jt.s
+++ b/bolt/test/RISCV/reloc-jt.s
@@ -1,6 +1,6 @@
 /// NOTE: assign section addresses explicitly to make the symbol difference
 /// calculation below less fragile.
-// RUN: %clang %cflags -Wl,--section-start=.text=0x1000,--section-start=.data=0x2000 -o %t %s
+// RUN: %clang %cflags -Wl,--image-base=0,--section-start=.text=0x1000,--section-start=.data=0x2000 -o %t %s
 // RUN: llvm-bolt -o %t.bolt %t
 // RUN: llvm-readelf -x .data %t.bolt | FileCheck %s
 
diff --git a/bolt/test/X86/double-rel-scan.s b/bolt/test/X86/double-rel-scan.s
index a8318d3c11862..77a55074a938b 100644
--- a/bolt/test/X86/double-rel-scan.s
+++ b/bolt/test/X86/double-rel-scan.s
@@ -6,7 +6,7 @@
 # REQUIRES: system-linux
 
 # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t.exe -q --Ttext=0x80000
+# RUN: ld.lld %t.o -o %t.exe -q --image-base=0x80000 --Ttext=0x80000
 # RUN: llvm-bolt %t.exe --relocs -o %t.bolt --funcs=foo
 # RUN: llvm-objdump -d --print-imm-hex %t.exe \
 # RUN:   | FileCheck %s
diff --git a/bolt/test/X86/double-rel.s b/bolt/test/X86/double-rel.s
index f7754f77e782b..f061515a632e3 100644
--- a/bolt/test/X86/double-rel.s
+++ b/bolt/test/X86/double-rel.s
@@ -5,7 +5,7 @@
 # REQUIRES: system-linux
 
 # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t.exe -q --Tdata=0x80000
+# RUN: ld.lld %t.o -o %t.exe -q --image-base=0x70000 --Tdata=0x80000
 # RUN: llvm-bolt %t.exe --relocs -o %t.null --print-only=_start --print-disasm \
 # RUN:   | FileCheck %s --check-prefix=CHECK-BOLT
 # RUN: llvm-objdump -d --print-imm-hex %t.exe \

@MaskRay MaskRay merged commit 744a469 into main May 21, 2025
12 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/bolttest-add-image-base-to-tests-that-use-section-start branch May 21, 2025 00:41
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 21, 2025
…tart

When using -no-pie without a SECTIONS command, the linker uses the
target's default image base. If -Ttext= or --section-start specifies an
output section address below this base, the result is likely unintended.
LLD will give a diagnostic (#140187) and may change the behavior in the future.
It's good to set an explicit image base to avoid relying on its current
behavior. BOLT doesn't seem to care whether a PT_PHDR segment is
present.

Pull Request: llvm/llvm-project#140570
MaskRay pushed a commit that referenced this pull request May 22, 2025
similar to #140570

getting this error:

exit status 1
ld.lld: error: section '.text' address (0x8074) is smaller than image
base (0x10000); specify --image-base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants